/*
 * ParamParser.h
 *
 *  Created on: Apr 15, 2011
 *      Author: sms103
 *
 * Simple parameter handling class. Maintains a map of parameters,
 * which are set initially through one or more param files.
 * Functions are made thread safe for use in SFTP because many
 * different layers running in different threads use the same
 * ParamParser object to set their parameters.
 *
 * Parameter file must contain one parameter per line. Whitespace is ignored.
 * A line beginning with a # is ignored.
 * Parameter lines are of the form: <paramName>  <paramValue>
 * example:
 * #this is the port number
 * portNumber 14000
 *
 * this will have map key "portNumber"
 */

#ifndef PARAMPARSER_H_
#define PARAMPARSER_H_

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <stdint.h>
#include <stdlib.h>
#include <pthread.h>

using namespace std;

class ParamParser {
public:
	ParamParser();

	//returns true if file is present and valid, false otherwise
	bool parseParams(const char * paramFileName);
	map<string,string> *getParamMap();

	void setLongIntParam(uint64_t *paramVariable, string mapKey,uint64_t defaultVal);
	void setIntParam(int *paramVariable, string mapKey,int defaultVal);
	void setDoubleParam(double *paramVariable, string mapKey,double defaultVal);
	void setStringParam(string *paramVariable, string mapKey,string defaultVal);

	//void setStringParam(string *paramVariable, string mapKey,string defaultVal);

	virtual ~ParamParser();
private:
	ifstream parFile;
	pthread_mutex_t paramMutex;
	map<string,string> *paramMap;
	map<string,string>::iterator it;
	ostringstream oss;//buffer for holding string version of param vals
};


#endif /* PARAMPARSER_H_ */
